﻿using Services.Input;
using UnityEngine;

namespace Hero
{
    public class HeroMove : MonoBehaviour
    {
        public float Speed { get; set; }

        private PlayerControls _controls;
        private IInputService _inputService;
        private Vector2 _move;
        private Vector3 _pos;

        public void Construct(IInputService inputService)
        {
            _inputService = inputService;
            _controls = _inputService.GetControls();
            _controls.Enable();
        }

        private void Update()
        {
            _move = _controls.Player.Move.ReadValue<Vector2>();
            _pos = transform.position;
        }

        private void FixedUpdate()
        {
            _pos += new Vector3(_move.x * Speed, 0, _move.y * Speed);
            if (transform != null) transform.position = _pos;
        }
    }
}